package mp

import (
	"duoke/service"
	"duoke/utils/gconv"
	"duoke/utils/request"
	"duoke/utils/response"
	"github.com/gin-gonic/gin"
	"github.com/gogf/gf/v2/os/gtime"
)

var Tool = new(sTool)

type sTool struct{}

func (ctl *sTool) TextToVoice(c *gin.Context) {
	userR, _ := service.Request.User(c)
	req := request.JsonMap(c)
	text := gconv.String(req["text"])
	if text == "" {
		response.Error(c, "text缺失", nil)
		return
	}
	voice, err := service.TxCloud.TextToVoice(text, gconv.String(userR)+gtime.Now().TimestampStr())
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "", voice)
}
